<template>
   <a-form-item :label="item.label" v-if="item.condition=='between'" style="margin-bottom:0;">
              <a-form-item :style="{ display:'inline-block', width: 'calc(50%)'}">
                <a-input style="width:100%" v-if="item.component=='input'" 
                  :disabled="item['disabled']"
                  v-decorator="[item.field+this.stSign,{rules:StringToJson(item['rules']),initialValue:item['initialValue']}]">
                </a-input>

                <LSelect style="width:100%" v-else-if="item.component=='select'" 
                  :mode="item['mode']"
                  :changeItem="changeItem" 
                  :parentSelect = "item['parentSelect']"
                  :dictParam = "item['dictParam']"
                  :dictCode = "item['dictCode']"
                  :disabled = "item['disabled']"
                  :field= "item['field']"
                  :replaceFields = "item['replaceFields']"
                  :form="form"
                  v-decorator="[item.field+this.stSign,{rules:StringToJson(item['rules']),initialValue:item['initialValue']}]">
              </LSelect>

              <LTreeSelect style="width:100%" v-else-if="item.component=='treeSelect'" 
                  :dictCode="item.dictCode"
                  :disabled="item['disabled']"
                  :dictParam = "item['dictParam']"
                  :treeCheckable = "item['treeCheckable']"
                  :multiple="item['multiple']"
                  v-decorator="[item.field+this.stSign,{rules:StringToJson(item['rules']),initialValue:item['initialValue']}]">
              </LTreeSelect>

              <a-input-number style="width: 100%" v-else-if="item.component=='inputNumber'"
                  :min="item['min']" 
                  :max="item['max']" 
                  :precision="item['precision']" 
                  :step="item['step'] || 1"
                  :disabled="item['disabled']"
                  v-decorator="[item.field+this.stSign,{rules:StringToJson(item['rules']),initialValue:item['initialValue']}]">
              </a-input-number>

              <a-date-picker style="width:100%;min-width:20px;" v-else-if="item.component=='date'"
                  :valueFormat="item['valueFormat'] || 'YYYY-MM-DD'"
                  :disabled="item['disabled']"
                  v-decorator="[item.field+this.stSign,{rules:StringToJson(item['rules']),initialValue:item['initialValue']}]"/>
              
              <a-month-picker style="width:100%;min-width:20px;" v-else-if="item.component=='month'"
                  :valueFormat="item['valueFormat'] || 'YYYY-MM'"
                  :disabled="item['disabled']"
                  v-decorator="[item.field+this.stSign,{rules:StringToJson(item['rules']),initialValue:item['initialValue']}]"/>

              
              <a-date-picker style="width:100%;min-width:20px;" show-time v-else-if="item.component=='time'"
                  :valueFormat="item['valueFormat'] || 'YYYY-MM-DD HH:mm:ss'"
                  :disabled="item['disabled']"
                  v-decorator="[item.field+this.stSign,{rules:StringToJson(item['rules']),initialValue:item['initialValue']}]"/>
              </a-form-item>
                

              <!--
              <span :style="{ display: 'inline-block', width: '24px', textAlign: 'center' }">-</span>
              -->
              <a-form-item :style="{ display: 'inline-block', width: 'calc(50%)' }">
                <a-input style="width:100%" v-if="item.component=='input'"
                  :disabled="item['disabled']"
                  v-decorator="[item.field+this.etSign,{rules:StringToJson(item['rules']),initialValue:item['initialValue']}]">
                </a-input>

                <LSelect style="width:100%" v-else-if="item.component=='select'" 
                  :mode="item['mode']"
                  :changeItem="changeItem" 
                  :parentSelect = "item['parentSelect']"
                  :dictCode = "item['dictCode']"
                  :disabled = "item['disabled']"
                  :field= "item['field']"
                  :replaceFields = "item['replaceFields']"
                  :form="form"
                  v-decorator="[item.field+this.etSign,{rules:StringToJson(item['rules']),initialValue:item['initialValue']}]">
              </LSelect>

              <LTreeSelect style="width:100%" v-else-if="item.component=='treeSelect'" 
                  :dictCode="item.dictCode"
                  :disabled="item['disabled']"
                  :treeCheckable = "item['treeCheckable']"
                  :multiple="item['multiple']"
                  v-decorator="[item.field+this.etSign,{rules:StringToJson(item['rules']),initialValue:item['initialValue']}]">
              </LTreeSelect>

              <a-input-number style="width: 100%" v-else-if="item.component=='inputNumber'"
                  :min="item['min']" 
                  :max="item['max']" 
                  :precision="item['precision']" 
                  :step="item['step'] || 1"
                  :disabled="item['disabled']"
                  v-decorator="[item.field+this.etSign,{rules:StringToJson(item['rules']),initialValue:item['initialValue']}]">
              </a-input-number>

              <a-date-picker style="width:100%;min-width:20px;" v-else-if="item.component=='date'"
                  :valueFormat="item['valueFormat'] || 'YYYY-MM-DD'"
                  :disabled="item['disabled']"
                  v-decorator="[item.field+this.etSign,{rules:StringToJson(item['rules']),initialValue:item['initialValue']}]"/>
              
              <a-month-picker style="width:100%;min-width:20px;" v-else-if="item.component=='month'"
                  :valueFormat="item['valueFormat'] || 'YYYY-MM'"
                  :disabled="item['disabled']"
                  v-decorator="[item.field+this.etSign,{rules:StringToJson(item['rules']),initialValue:item['initialValue']}]"/>

                
              <a-date-picker style="width:100%;min-width:20px;" show-time v-else-if="item.component=='time'"
                  :valueFormat="item['valueFormat'] || 'YYYY-MM-DD HH:mm:ss'"
                  :disabled="item['disabled']"
                  v-decorator="[item.field+this.etSign,{rules:StringToJson(item['rules']),initialValue:item['initialValue']}]"/>

              </a-form-item>
              

          </a-form-item>

           <a-form-item :label="item.label" v-else>

              <a-input style="width:100%" v-if="item.component=='input'" 
                :disabled="item['disabled']"
                v-decorator="[item.field,{rules:StringToJson(item['rules']),initialValue:item['initialValue']}]">
              </a-input>

              <LSelect style="width:100%" v-else-if="item.component=='select'" 
                  :mode="item['mode']"
                  :changeItem="changeItem" 
                  :parentSelect = "item['parentSelect']"
                  :dictCode = "item['dictCode']"
                  :dictParam = "item['dictParam']"
                  :disabled = "item['disabled']"
                  :field= "item['field']"
                  :replaceFields = "item['replaceFields']"
                  :form="form"
                  v-decorator="[item.field,{rules:StringToJson(item['rules']),initialValue:item['initialValue']}]">
              </LSelect>


              <LTreeSelect  v-else-if="item.component=='treeSelect'" 
                  style="width: 100%"
                  :dictCode="item.dictCode"
                  :disabled="item['disabled']"
                  :dictParam = "item['dictParam']"
                  :treeCheckable = "item['treeCheckable']"
                  :multiple="item['multiple']"
                  v-decorator="[item.field,{rules:StringToJson(item['rules']),initialValue:item['initialValue']}]">
              </LTreeSelect>

              <a-input-number v-else-if="item.component=='inputNumber'"
                  style="width: 100%"
                  :min="item['min']" 
                  :max="item['max']" 
                  :precision="item['precision']" 
                  :step="item['step'] || 1"
                  :disabled="item['disabled']"
                  v-decorator="[item.field,{rules:StringToJson(item['rules']),initialValue:item['initialValue']}]">
              </a-input-number>

              <a-date-picker  v-else-if="item.component=='date'"
                   style="width: 100%"
                  :valueFormat="item['valueFormat'] || 'YYYY-MM-DD'"
                  :disabled="item['disabled']"
                  v-decorator="[item.field,{rules:StringToJson(item['rules']),initialValue:item['initialValue']}]"/>
              
              <a-month-picker  v-else-if="item.component=='month'"
                  style="width: 100%"
                  :valueFormat="item['valueFormat'] || 'YYYY-MM'"
                  :disabled="item['disabled']"
                  v-decorator="[item.field,{rules:StringToJson(item['rules']),initialValue:item['initialValue']}]"/>

              <a-date-picker style="width: 100%"  show-time v-else-if="item.component=='time'"
                  :valueFormat="item['valueFormat'] || 'YYYY-MM-DD HH:mm:ss'"
                  :disabled="item['disabled']"
                  v-decorator="[item.field,{rules:StringToJson(item['rules']),initialValue:item['initialValue']}]"/>
                <a-time-picker style="width: 100%" show-time v-else-if="item.component=='timePicker'"
                    :valueFormat="item['valueFormat'] || 'HH:mm:ss'"
                    :disabled="item['disabled']"
                    v-decorator="[item.field,{rules:StringToJson(item['rules']),initialValue:item['initialValue']}]"/>
    </a-form-item>
</template>

<script>

import LSelect from '@/components/lt/LSelect'
import LTreeSelect from '@/components/lt/LTreeSelect'
import LSearchSelect from '@/components/lt/LSearchSelect'
import {StringToJson} from '@/utils/util'

export default {
    name:'LQueryFormItem',
    components:{LSelect,LTreeSelect,LSearchSelect},
    data(){
        return{
            //范围查询时，给字典名加上后缀
            stSign:"_st",
            etSign:"_et"
        }
    },
    created(){
      
        
    },
    props:{
        item:{
            type:Object,
            default:()=>{}
        },
        changeItem:{
            type:Object,
            default:()=>{}
        },
        form:{
            type:Object,
            default:()=>{} 
        }, 
        
    },
    methods:{
       StringToJson(str){
            if(str){
              str =  StringToJson(str)
            }
            return str
        },
        
    }
}

</script>
